<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      let str = "<div>我的{{name}}今年{{ age }}岁</div>";
      let pattern = /{{\s*([a-zA-Z]+)\s*}}/;
      // 第一次匹配
      let res1 = pattern.exec(str);
      str = str.replace(res1[0], res1[1]);
      console.log(str); //<div>我的name今年{{ age }}岁</div>
      // 第二次匹配
      let res2 = pattern.exec(str);
      str = str.replace(res2[0], res2[1]);
      console.log(str); // <div>我的name今年age岁</div>
      // 第三次匹配
      let res3 = pattern.exec(str);
      console.log(res3); // null
    </script>
  </body>
</html>
